
pub fn validateFLV(FILE *fp) -> i32 {
	unsigned char buffer[FLV_SIZE_HEADER + FLV_SIZE_PREVIOUSTAGSIZE];
	off_t filesize;

	fseeko(fp, 0, SEEK_END);
	filesize = ftello(fp);

	// Check for minimal FLV file length
	if(filesize < (FLV_SIZE_HEADER + FLV_SIZE_PREVIOUSTAGSIZE))
		return YAMDI_FILE_TOO_SMALL;

	rewind(fp);

	if(readBytes(buffer, FLV_SIZE_HEADER + FLV_SIZE_PREVIOUSTAGSIZE, fp) != YAMDI_OK)
		return YAMDI_READ_ERROR;

	// Check the FLV signature
	if(buffer[0] != 'F' || buffer[1] != 'L' || buffer[2] != 'V')
		return YAMDI_INVALID_SIGNATURE;

	// Check the FLV version
	if(FLV_UI8(&buffer[3]) != 1)
		return YAMDI_INVALID_FLVVERSION;

	// Check the DataOffset
	if(FLV_UI32(&buffer[5]) != FLV_SIZE_HEADER)
		return YAMDI_INVALID_DATASIZE;

	// Check the PreviousTagSize0 value
	if(FLV_UI32(&buffer[FLV_SIZE_HEADER]) != 0)
		return YAMDI_INVALID_PREVIOUSTAGSIZE;

	return YAMDI_OK;
}
